home *** CD-ROM | disk | FTP | other *** search
/ Hacker's Arsenal - The Cutting Edge of Hacking / Hacker's Arsenal - The Cutting Edge of Hacking.iso / texts / misc / passsec.txt < prev    next >
Encoding:
Text File  |  2001-07-11  |  11.6 KB  |  339 lines

  1. :Taken from CoTNO 5:
  2.  
  3. <CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>
  4.                  
  5.                  
  6.                      
  7.                      Notes on Unix Password Security
  8.                                   by
  9.                                 Voyager
  10.                           will@gnu.ai.mit.edu
  11.  
  12.  
  13. Introduction
  14. ~~~~~~~~~~~~
  15. Standard Unix implementations keep user passwords in the file
  16. /etc/passwd.  An entry in the password file consists of seven colon
  17. delimited fields:
  18.  
  19. Username
  20. Encrypted password (And optional password aging data)
  21. User number
  22. Group Number
  23. GECOS Information
  24. Home directory
  25. Shell
  26.  
  27. ]
  28. ] Sample entry from /etc/passwd:
  29. ]
  30. ] will:5fg63fhD3d:9406:12:Will Spencer:/home/fsg/will:/bin/bash
  31. ]
  32.  
  33. Broken down, this passwd file line shows:
  34.  
  35.           Username: will
  36. Encrypted password: 5fg63fhD3d
  37.        User number: 9406
  38.       Group Number: 12
  39.  GECOS Information: Will Spencer
  40.     Home directory: /home/fsg/will
  41.              Shell: /bin/bash
  42.  
  43.  
  44. Password Aging
  45. ~~~~~~~~~~~~~~
  46. On some systems you will find passwd entries with password aging
  47. installed. Password aging forces the user to change passwords after a
  48. System Administrator specified period of time.  Password aging can
  49. also force a user to keep a password for a certain number of weeks
  50. before changing it.
  51.  
  52. ]
  53. ] Sample entry from /etc/passwd with password aging installed:
  54. ]
  55. ] will:5fg63fhD3d,M.z8:9406:12:Will Spencer:/home/fsg/will:/bin/bash
  56. ]
  57.  
  58. Note the comma in the encrypted password field.  The characters after
  59. the comma are used by the password aging mechanism.
  60.  
  61. ]
  62. ] Password aging characters from above example:
  63. ]
  64. ] M.z8
  65. ]
  66.  
  67. The four characters are interpreted as follows:
  68.  
  69.   1: Maximum number of weeks a password can be used before changing
  70.   2: Minimum number of weeks a password must be used before changing
  71. 3&4: Last time password was changed, in number of weeks since 1970/1/1
  72.  
  73. Three special cases should be noted:
  74.  
  75. If the first and second characters are set to '..' the user will be
  76. forced to change his/her passwd the next time he/she logs in.  The
  77. passwd program will then remove the passwd aging characters, and the
  78. user will not be subjected to password aging requirements again.
  79.  
  80. If the third and fourth characters are set to '..' the user will be
  81. forced to change his/her passwd the next time he/she logs in. Password
  82. aging will then occur as defined by the first and second characters.
  83.  
  84. If the first character (MAX) is less than the second character (MIN),
  85. the user is not allowed to change his/her password.  Only root can
  86. change that users password.
  87.  
  88. It should also be noted that the su command does not check the
  89. password aging data.  An account with an expired password can be su'd
  90. to without being forced to change the password.
  91.  
  92. The password aging codes are in base-64 format, and can be converted to
  93. decimal using the following table:
  94.  
  95.                         Password Aging Codes
  96. +------------------------------------------------------------------------+
  97. |                                                                        |
  98. | Character:  .  /  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F  G  H |
  99. |    Number:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 |
  100. |                                                                        |
  101. | Character:  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  a  b |
  102. |    Number: 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
  103. |                                                                        |
  104. | Character:  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v |
  105. |    Number: 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
  106. |                                                                        |
  107. | Character:  w  x  y  z                                                 |
  108. |    Number: 60 61 62 63                                                 |
  109. |                                                                        |
  110. +------------------------------------------------------------------------+
  111.  
  112.  
  113. Password Aging Defaults
  114. ~~~~~~~~~~~~~~~~~~~~~~~
  115. System wide defaults for password aging are stored in the file
  116. /etc/default/passwd.
  117.  
  118. ]
  119. ] Sample entry from /etc/default/passwd under System V release 4.0
  120. ]
  121. ] MINWEEKS=0
  122. ] MAXWEEKS=500
  123. ] PASSLENGTH=5
  124. ] WARNWEEKS=1
  125. ]
  126.  
  127. MINWEEKS is the default minimum number of weeks a password must be
  128. used before changing.  MAXWEEKS is the default maximum number of weeks
  129. a password can be used before changing.  PASSLENGTH is the minimum
  130. number of characters a password may contain.  WARNWEEKS, which did not
  131. exist prior to System V Release 4, is the number of weeks a user is
  132. warned that they must change their password.
  133.  
  134.  
  135. Password Shadowing
  136. ~~~~~~~~~~~~~~~~~~
  137. Due to basic design aspects of the Unix system, the file /etc/passwd
  138. is world readable.  This allows password crackers to steal the
  139. encrypted passwords and attempt to crack them.  Newer versions of Unix
  140. use a scheme known as shadowing to alleviate this problem.
  141.  
  142. On a Unix system with password shadowing, the encrypted password field
  143. of the password file is replaced by a special token.  When the login
  144. and passwd programs see this token in the password field, they switch
  145. to the shadowed copy of the password file for the actual encrypted
  146. password field. The shadowed copy of the password file is readable
  147. only by root and the login and passwd programs run SUID root.
  148.  
  149.  
  150. Defeating Password Shadowing
  151. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  152. Password shadowing can be defeated on some systems by using
  153. getpwent(), as in the following program.  Successive calls to
  154. getpwent() are made for every line in the passwd file.  This method
  155. only works for older password shadowing schemes.
  156.  
  157. ] #include <pwd.h>
  158. ] main()
  159. ] {
  160. ] struct passwd *p;
  161. ] while(p=getpwent())
  162. ] printf("%s:%s:%d:%d:%s:%s:%s\n", p->pw_name, p->pw_passwd,
  163. ] p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
  164. ] }
  165.  
  166.  
  167. On systems where getpwent() fails, it is possible to utilize the
  168. pwdauth() function for similar purposes.  Note that the pwdauth()
  169. function is purposefully designed to operate very slowly.  This
  170. program shows the basics of pwdauth(), for a more complete example of
  171. a cracker utilitizing pwdauth() refer to Shadow Crack from The
  172. Shining/UPi.
  173.  
  174. ]
  175. ] #define MAXLOGIN 8
  176. ] #define MAXPASS 8
  177. ]
  178. ] main()
  179. ] {
  180. ]
  181. ] char login[MAXLOGIN];
  182. ] char password[MAXPASS];
  183. ] printf("login: ");
  184. ] scanf("%s", login);
  185. ] printf("password: ");
  186. ] scanf("%s", password);
  187. ]  
  188. ]
  189. ] if (pwdauth(login,password) == 0 )
  190. ]     printf("Correct!\n");
  191. ]     else printf("Wrong!\n");
  192. ] }
  193.  
  194.  
  195. A third method of defeating password shadowing is to have root
  196. priveleges, as root is able to read the shadowed password file
  197. directly.
  198.  
  199. The following chart show the location of the shadowed password
  200. information and the token left in the /etc/passwd file by various
  201. versions of Unix.
  202.  
  203. ]
  204. ] Unix                  Path                            Token
  205. ] -----------------------------------------------------------------
  206. ] AIX 3                 /etc/security/passwd            !
  207. ]        or             /tcb/auth/files/<first letter   #
  208. ]                             of username>/<username>
  209. ] A/UX 3.0s             /tcb/files/auth/?/*
  210. ] BSD4.3-Reno           /etc/master.passwd              *
  211. ] ConvexOS 10           /etc/shadpw                     *
  212. ] ConvexOS 11           /etc/shadow                     *
  213. ] DG/UX                 /etc/tcb/aa/user/               *
  214. ] EP/IX                 /etc/shadow                     x
  215. ] HP-UX                 /.secure/etc/passwd             *
  216. ] IRIX 5                /etc/shadow                     x
  217. ] Linux 0.99            /etc/shadow                     *
  218. ] OSF/1                 /etc/passwd[.dir|.pag]          *
  219. ] SCO UNIX R3.2v4.2     /etc/shadow                     x
  220. ] SCO Unix 3.2.x        /tcb/auth/files/<first letter   *
  221. ]                             of username>/<username>
  222. ] SunOS 4.1+c2          /etc/security/passwd.adjunct    ##username
  223. ] SunOS 5.0             /etc/shadow
  224. ]                       <optional NIS+ private secure maps/tables/whatever>
  225. ] System V Release 3.2  /etc/shadow                     x
  226. ] System V Release 4.0  /etc/shadow                     x
  227. ] System V Release 4.2  /etc/security/* database
  228. ] Ultrix 4              /etc/auth[.dir|.pag]            *
  229. ] UNICOS                /etc/udb                        *
  230. ]
  231.  
  232.  
  233. Format of the shadowed password file
  234. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  235. The format of the shadowed password file differs under various Unix
  236. implementations.  Many implementations follow the original System V
  237. Release 3.2, while others opt for a more complicated yet more
  238. efficient database structure.
  239.  
  240. An entry in the System V Release 3.2 shadow file consists of five
  241. colon delimited fields:
  242.  
  243. Username
  244. Encrypted password (And optional password aging data)
  245. Last time password was changed, in number of days since 1970/1/1
  246. Minimum number of days a password must be used before changing
  247. Maximum number of days a password can be used before changing
  248.  
  249. System V Release 4 introduced three more fields to the shadow file:
  250.  
  251. The number of days before the password expires that the user will be warned
  252. The number of days of inactivity allowed for the user
  253. The absolute expiration date for the account
  254.  
  255. ]
  256. ] Sample entry from /etc/shadow under System V release 4.0
  257. ]
  258. ] will:5fg63fhD3d:8960:1:60:10:90:10000
  259. ]
  260.  
  261. Broken down, this shadow file line shows:
  262.  
  263.           Username: will
  264. Encrypted password: 5fg63fhD3d
  265.        Last change: 8960  (Password was last changed on
  266.       Minimum days: 1     (Password must be kept for 1 day without changing)
  267.       Maximum days: 60    (Password must be changed every 60 days)
  268.       Warning days: 10    (User receives 10 days warning of required
  269.                            password change)
  270.    Inactivity days: 90    (Account disabled if not used for 90 days)
  271.    Expiration date: 10000 (Account expires on
  272.  
  273.  
  274. The SunOS adjunct system
  275. ~~~~~~~~~~~~~~~~~~~~~~~~
  276. Sun Microsystems introduced changes in their version of the shadow
  277. file in SunOS 4.1.
  278.  
  279. An entry in the SunOS passwd.adjunt file consists of seven colon
  280. delimited fields:
  281.  
  282. Username
  283. Encrypted password (And optional password aging data)
  284.  
  285. ]
  286. ] Sample entry from /etc/security/passwd.adjunt under SunOS 4.1
  287. ]
  288. ] will:5fg63fhD3d::::ad,p0,p1:dr,dw,dc,da,lo
  289. ]
  290.  
  291. Broken down, this passwd.adjunt line shows:
  292.  
  293.                Username: will
  294.      Encrypted password: 5fg63fhD3d
  295. Minimum login clearance:
  296. Maximum login clearance:
  297. Default login clearance:
  298.            Always audit: ad,p0,p1
  299.             Never audit: dr,dw,dc,da,lo
  300.  
  301.  
  302. NIS
  303. ~~~
  304. NIS (Network Information System) in the current name for what was once
  305. known as yp (Yellow Pages).  The purpose for NIS is to allow many
  306. machines on a network to share configuration information, including
  307. password data.  NIS is not designed to promote system security.  If
  308. your system uses NIS you will have a very short /etc/passwd file that
  309. includes a line that looks like this:
  310.  
  311. +::0:0:::
  312.  
  313. To view the real password file use this command "ypcat passwd"
  314.  
  315.  
  316. Password cracking
  317. ~~~~~~~~~~~~~~~~~
  318. Contrary to popular belief, Unix passwords cannot be decrypted.  Unix
  319. passwords are encrypted with a one way function.  The login program
  320. encrypts the text you enter at the "password:" prompt and compares
  321. that encrypted string against the encrypted form of your password.
  322.  
  323. Password cracking software uses wordlists.  The password cracking
  324. program encrypts each word in the wordlist and compares that encrypted
  325. string against the encrypted form of the password.  If the encrypted
  326. forms match, the password is known.
  327.  
  328. To crack passwords, you will need a password cracking program and a
  329. wordlist.  The best cracking program for Unix passwords is currently
  330. Crack by Alec Muffett.  For PC-DOS, the best package to use is
  331. currently CrackerJack.  Larger wordlists will allow you to crack more
  332. accounts.
  333.  
  334.  
  335.  
  336.